package com.kotlin.book.adapter

import androidx.fragment.app.Fragment
import androidx.viewpager2.adapter.FragmentStateAdapter
import com.kotlin.book.entry.Type
import com.kotlin.book.fragments.HomeFragmentIndex
import com.kotlin.book.fragments.HomeFragmentItem

class HomeFragmentAdapter(
    fragment: Fragment,
    private val items: List<Type>
) : FragmentStateAdapter(fragment) {

    override fun getItemCount(): Int {
        return items.size
    }

    override fun createFragment(position: Int): Fragment {
        // 创建并返回对应位置的 Fragment
        if(position==0){
            return HomeFragmentIndex()
        }else{
            return HomeFragmentItem(items[position])
        }
    }
}